<?php

class report {

  function reportLink (&$shop,$params) {
     if ($params[0]){
       $link = '<a href="'.$shop->getVar('SCRIPT_NAME').'?a=sr&rid=<%=$id%>&tr=<%=$TEMPLATE_ROOT%>&t='.$shop->cfgTpl['report'].'" target="'.$shop->cfgTplFrame['report'].'">'.$params[0].'</a>';
       $link = $shop->mod['parser']->evalVars($link);
       $shop->out($link);
     } else {
       $shop->out("<b>columnLink: erster Parameter fehlt</b><br>");
     }
  }

  function getReport (&$shop,$params) {
      global $shop;
      $report = $shop->call('dbaBerichte','getBericht',$shop->getSessionVar('currentReport'));
      if ($report){
        while (list($name,$value) = each($report)){
	  if (!preg_match('/^\d+$/',$name)){
	   $shop->setBlockVar($name,$value);
	  }
	}
        return true;
      }
  }

  function getReports (&$shop,$params = '') {
      $this->reports = $shop->call('dbaBerichte','getPubBerichteByRubrik',$shop->getSessionVar('currentColumn'));
      $this->reportcount = 0;
      if ($this->reports){
        return true;
      }
  }

  function nextReport (&$shop,$params = '') {
     if ($this->reportcount < count($this->reports)){
        while (list($name,$value) = each($this->reports[$this->reportcount])){
	  if (!preg_match('/^\d+$/',$name)){
           if (($name == 'text') && $params[0]){
             $value = $this->_filterText($value,$params[0],$params[1]);
           }
	   $shop->setBlockVar($name,$value);
	  }
	}
	$this->reportcount++;
        return true;
     } else {
        unset($this->reports);
	return;
     }
  }

  function getReportsHome (&$shop,$params = '') {
      $this->homereports = $shop->call('dbaBerichte','getBerichteHome');
      $this->homereportcount = 0;
      if ($this->homereports){
        return true;
      }
  }

  function nextReportHome (&$shop,$params = '') {
     if ($this->homereportcount < count($this->homereports)){
        while (list($name,$value) = each($this->homereports[$this->homereportcount])){
	  if (!preg_match('/^\d+$/',$name)){
           if (($name == 'text') && $params[0]){
             $value = $this->_filterText($value,$params[0],$params[1]);
           }
	   $shop->setBlockVar($name,$value);
	  }
	}
	$this->homereportcount++;
        return true;
     } else {
        unset($this->homereports);
	return;
     }
  }

  function _filterText ($text,$maxlength,$postfix) {
     $length = strlen(strip_tags($text));
     $text   = strip_tags($text,'<b><i><h1><h2><h3><h4><h5><h6><h7><u><strong><font><span>');
     $text   = substr($text,0,$maxlength);
     if ($length > strlen(strip_tags($text))) {
       $value  = preg_replace('/\w+$/',"",$text);
       $value .= $postfix;
     }
     return $value;
  }

}

?>